<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>选择收件材料</title>

<%@ include file="/wf/public/meta_wf.jsp"%>
<script src="${ctx}/resources/js/aos/public.js" type="text/javascript"></script>
<script src="${ctx}/gzcgwsp/resources/js/prototype.js" type="text/javascript"></script>
<script src="${ctx}/resources/components/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="${ctx}/gzcgwsp/resources/css/common-ui.css" />
<script src="${ctx}/resources/js/jquery/jquery.js" type="text/javascript"></script>
<script src="${ctx}/gzcgwsp/resources/js/YwUtil.js" type="text/javascript"></script>
<script src="${ctx}/resources/js/aos/tool.js" type="text/javascript"></script>

<script>
//页面加载时，初始化CheckBox
function initCheckedIdsCheckBox(){
	var checkedsStr = '${checkedsStr}';//所有选中name="checkedIds"的input对象组成的字符串
	var url="${ctx}/smart-form-shljqs!checkSjtzs.action?id=${id}&templateCode=${templateCode}&fileCode=sjtzs";
    	$.ajax({
		url : url,
		type : "post",
		dataType : "html",
		success : function(msg) {
			if(msg=="exsit"){
			   	var checkedsStrArr = checkedsStr.split("===");//分割成数组
				var checkedIds = document.getElementsByName("checkedIds");//本页面上name="checkedIds"的所有input对象组成的数组
				for(var i = 0;i<checkedsStrArr.length;i++){
					for(var j = 0;j<checkedIds.length;j++){
						if(checkedIds[j].value == checkedsStrArr[i]){
							checkedIds[j].checked = true;
						}
					}
				}
			}else{
				var checkedIds = document.getElementsByName("checkedIds");//本页面上name="checkedIds"的所有input对象组成的数组
					for(var j = 0;j<checkedIds.length;j++){
						checkedIds[j].checked = true;
					}
			}			
		},
		error:function() {
			alert("添加失败！请刷新重试！");
		}
	});

}
//保存收件通知书
function saveSjtzs(){
	var params = $("#preViewSjtzsForm").serialize();
	var url="${ctx}/smart-form-shljqs!saveSjtzs.action";
	$.ajax({
		url : url,
		type : "post",
		dataType : "html",
		data : params,
		success : function(msg) {
			var msgArr = msg.split("&&");
			if(msgArr[0]=="success"){
				var aa = msgArr[1];
				document.getElementById("path").value = aa;
				alert('保存成功!');
			}else{
				alert('保存失败！');
			}			
		},
		error:function() {
			alert("添加失败！请刷新重试！");
		}
	});
}

//打印收件通知书
function printSjtzs(){
    	var action = '${ctx}/smart-form-shljqs!printcz.action?id=${id}&templateCode=${templateCode}&fileCode=sjtzs&activName=${activName}';
	 	var url="${ctx}/smart-form-shljqs!checkSjtzs.action?id=${id}&templateCode=${templateCode}&fileCode=sjtzs";
    	$.ajax({
		url : url,
		type : "post",
		dataType : "html",
		success : function(msg) {
			if(msg=="exsit"){
			    window.open( action);
			}else{
				alert('请先保存！');
			}			
		},
		error:function() {
			alert("添加失败！请刷新重试！");
		}
	});
}


// 选中所有记录
function checkAll(chxEvent) {
  var chxs = document.forms[0].checkedIds;
  if (chxs && !chxs.length) { chxs.checked = chxEvent.checked; return; }
  if (chxs) for (var i = 0; i < chxs.length; i++) {
    chxs[i].checked = chxEvent.checked;
  }
}

</script>
</head>

<body onload="initCheckedIdsCheckBox();">
<form action="" method="post" id="preViewSjtzsForm">
	<input type="hidden" name="templateCode" value="${templateCode}"/>
	<input type="hidden" name="checkedsStr" value="${checkedsStr}"/>
	<input type="hidden" name="activName" id="activName" value="${activName}"/>
	<input type="hidden" name="path" id="path" value="${path}"/>
	<input type="hidden" name="id" value="${id}"/>
	<center>
	</br>
	<font >请选择已提交的纸制材料</font>
  <table width="850" border="0" cellspacing="2" cellpadding="2">    
    <tr>
      <td>
       <table width="100%" border="1" cellspacing="2" cellpadding="2" class="tpl_list_blueui">
          <tr>
            <td height="20" bordercolor="#B3D9D9" bgcolor="#D9E8FB">
              <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="50%">&nbsp;&nbsp;<b>材料列表</b></td>
                  <td width="50%" align="right">
                    <table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolor="#D9E8FB">
                      <tr>
                        <td height="20">&nbsp;</td>                     
                        <td width="80">
                          <table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolor="#D9E8FB" onmouseover="this.className='tpl_btn_omover'" onmousedown="this.className='tpl_btn_omdown'" onmouseout="this.className='tpl_btn_omout'" onclick="RecordReset();">
                            <tr>
                              <td height="20" align="center" style="padding-right:50px;">
                              </td>
                            </tr>
                          </table>
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
            </table></td>
          </tr>
      </table></td>
    </tr>
    <tr>
      <td><table width="100%" border="1" cellspacing="2" cellpadding="2" class="tpl_list_blueui">
        <tr>
          <td  width="8%" align="center" bordercolor="#B3D9D9" bgcolor="#E7EEF8">序号</td>
          <td width="60%" align="center" bordercolor="#B3D9D9" bgcolor="#E7EEF8">附件名称</td>
          <td width="20%" align="left" bordercolor="#B3D9D9" bgcolor="#E7EEF8">
	         <input type="checkbox" id="checkall"  onclick="checkAll(this)" /> 
	          是否提交纸制材料
          </td>
        </tr>
        <c:forEach var="sjclForm" items="${sjclList}" varStatus="stat">
          <tr style="${(stat.index % 2) ne 0 ? 'background-color: #FFFFD7;' : ''}">
            <td align="center" bordercolor="#B3D9D9">${stat.index + 1}</td>
            <td bordercolor="#B3D9D9">${sjclForm.title}</td>
            <td align="left" bordercolor="#B3D9D9">
            	<input type="checkbox"  name="checkedIds" value="${sjclForm.id}"/>
            </td>
          </tr>
        </c:forEach>
      </table>
     </td>
    </tr>    
  </table>
  	<br />
  	<input id="saveButton" type="button" value="保存" style="width:100px;" onclick="saveSjtzs()"/>
	<input id="printButton" type="button" value="打印" onclick="printSjtzs();" style="width:100px;"/>
	<input type="button" value="关闭窗口" onclick="window.close();" style="width:100px;"/>
</center>
</form>
</body>
</html>
